var roleE10S58_H_I = {
    run: function(creep) {

        //creep.say(creep.memory.building);

        if(creep.store.getUsedCapacity()==0){
            creep.memory.building = true;
        }
        if(creep.store.getFreeCapacity()==0){
            creep.memory.building = false;
        }


        if(creep.memory.building == true){
            if(creep.room.name != 'E10S58'){
                //creep.say('555555');
                creep.moveTo(Game.flags['E10S58'].pos, {reusePath:10});
            }
            else{
                //creep.say('3213211kkk');
                var sources = creep.room.find(FIND_DEPOSITS);
                //creep.say('3213211kkk2');
                if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
                    creep.moveTo(sources[0], {reusePath:10});
                }
            }
        }
        else{     
                //运矿回去
                //creep.say('ooooooo');
                    if(creep.room.name != 'E9S58'){
                        //creep.say(321);
                        creep.moveTo(Game.flags['E9S58'].pos, {reusePath:10});
                    }
                    else{
                        var targetsstorage = creep.room.find(FIND_STRUCTURES, {
                            filter: (structure) => {
                                return (structure.structureType == STRUCTURE_TERMINAL) && 
                                structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0;
                            }
                        });
                        if(targetsstorage.length > 0) {
                            if(creep.transfer(targetsstorage[0], RESOURCE_BIOMASS) == ERR_NOT_IN_RANGE) {
                                creep.moveTo(targetsstorage[0], {reusePath:10});
                                //creep.say('搬去');
                            }
                        }
                    }
        }
	}
};

module.exports = roleE10S58_H_I;